<?php
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

$pid = getgpc('pid');
if (!isset($pid) ){
	$pid = 4;
}

$topic_list = array();
$topic_ids = array();
$sql = "select * from t_topic where parent_id = $pid";
$query = DB::query($sql);
while($row = DB::fetch($query)) {
	$topic_list[] = $row;
	$topic_ids[] = $row['id'];
}
DB::free_result($query);

$tid = $_G["gp_tid"];
if (!isset($tid) || !in_array($tid, $topic_ids)){
	$tid = $topic_ids[0];
}
$subject = '育婴周刊   怀孕'.$topic_list[0]['title'].'注意事项';
foreach ($topic_list as $topic){
	if ($tid == $topic['id']) {
		$subject = '育婴周刊  怀孕 '.$topic['title'].' 注意事项';
		break;
	}
}


$show_pre_article = false;
$show_next_article = false;
// 该topic文章数量不为空。
if(count($topic_list) > 0 ){
	if ($tid > $topic_ids[0] ){
		$show_pre_article = true;
	}
	if ($tid < $topic_ids[count($topic_ids) - 1] ){
		$show_next_article = true;
	}
}
$pre_tid = intval($tid) - 1;
$next_tid = intval($tid) + 1;

$article_list = array();
$article = array();
$article_title = "";
if(isset($tid)){
	$sql = " select p.id,p.article_id,a.title as article_title, p.title, p.content, p.content_new_line, p.paragraph_level from t_article a
	left join t_paragraph p on a.id = p.article_id where a.topic_id = $tid order by p.article_id,p.id asc ";
	$paragraph_list = array();
	$query = DB::query($sql);
	while($row = DB::fetch($query)) {
		$paragraph_list[] = $row;
		if ($article_title != $row['article_title']){
			$article['id'] =  $row['article_id'];
			$article['topic_id'] =  $row['id'];
			$article['title'] =  $row['article_title'];
			$article_list[]  = $article;
			
			$article_title = $article['title'];
		}
	}
	DB::free_result($query);
}

include_once template("know/viewweekly");

?>